Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
The has-values npm package is a utility that checks if a value exists and is not empty. It can be used to validate objects, arrays, strings, and other data types to ensure they contain meaningful data.
Check if a string has a value
This feature allows you to check if a string is non-empty. It returns true if the string has a value and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues('hello')); // true
console.log(hasValues('')); // false
Check if an array has values
This feature checks if an array contains any elements. It returns true if the array has elements and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues([1, 2, 3])); // true
console.log(hasValues([])); // false
Check if an object has values
This feature checks if an object has any properties. It returns true if the object has properties and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues({a: 1, b: 2})); // true
console.log(hasValues({})); // false
Check if a nested object has values
This feature checks if a nested object contains any values. It returns true if the nested object has values and false if it is empty.
const hasValues = require('has-values');
console.log(hasValues({a: {b: 2}})); // true
console.log(hasValues({a: {}})); // false
Lodash is a popular utility library that provides a wide range of functions for manipulating and validating data. It includes methods like _.isEmpty, which can be used to check if a value is empty, similar to has-values.
Underscore is another utility library that offers a variety of functions for working with arrays, objects, and other data types. It includes the _.isEmpty method, which serves a similar purpose to has-values by checking if a value is empty.
Validator is a library focused on string validation and sanitization. It includes functions like isEmpty, which can be used to check if a string is empty, similar to the functionality provided by has-values.
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
Install with npm:
$ npm install has-values --save
var hasValue = require('has-values');
hasValue('a');
//=> true
hasValue('');
//=> false
hasValue(1);
//=> true
hasValue(0);
//=> false
hasValue(0, true); // treat zero as a value
//=> true
hasValue({a: 'a'}});
//=> true
hasValue({}});
//=> false
hasValue(['a']);
//=> true
hasValue([]);
//=> false
hasValue(function(foo) {}); // function length/arity
//=> true
hasValue(function() {});
//=> false
hasValue(true);
hasValue(false);
//=> true
To test for empty values, do:
function isEmpty(o, isZero) {
return !hasValue(o, isZero);
}
You might also be interested in these projects:
Object
constructor. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v, on March 27, 2016.
FAQs
Returns true if any values exist, false if empty. Works for booleans, functions, numbers, strings, nulls, objects and arrays.
We found that has-values demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.